﻿@page
@model RegisterModel
@{
    ViewData["Title"] = "注册";
}
    <style type="text/css">
        .mdui-textfield-error {
            visibility: visible;
        }

        .mdui-textfield .mdui-icon ~ .mdui-textfield-error {
            margin-left: 0;
        }
    </style>
<form id="form1"  method="post">
    <div class="mdui-container-fluid">
        <div class="mdui-row">
            <div class="mdui-col-sm-6 mdui-col-offset-sm-3 mdui-col-md-4 mdui-col-offset-md-4 mdui-m-t-3">
                <div class="mdui-card" style="border-radius:5px;">
                    <div class="mdui-card-content">
                        <div class="mdui-textfield mdui-textfield-floating-label">
                            <label asp-for="Input.Email" class="mdui-textfield-label"></label>
                            <input asp-for="Input.Email" class="mdui-textfield-input mdui-color-grey-100" />
                            <i class="mdui-icon material-icons" style="position:absolute;right:0;">account_circle</i>
                            <span asp-validation-for="Input.Email" class="mdui-textfield-error"></span>
                        </div>
                        <div class="mdui-textfield mdui-textfield-floating-label">
                            <label asp-for="Input.Password" class="mdui-textfield-label"></label>
                            <input asp-for="Input.Password" class="mdui-textfield-input mdui-color-grey-100" />
                            <i class="mdui-icon material-icons" style="position:absolute;right:0;">lock_outline</i>
                            <span asp-validation-for="Input.Password" class="mdui-textfield-error"></span>
                        </div>
                        <div class="mdui-textfield mdui-textfield-floating-label">
                            <label asp-for="Input.ConfirmPassword" class="mdui-textfield-label"></label>
                            <input asp-for="Input.ConfirmPassword" class="mdui-textfield-input mdui-color-grey-100" />
                            <i class="mdui-icon material-icons" style="position:absolute;right:0;">lock_outline</i>
                            <span asp-validation-for="Input.ConfirmPassword" class="mdui-textfield-error"></span>
                        </div>
                    </div>
                    <div class="mdui-card-actions">
                        <button id="btn_register" type="button" class="mdui-btn mdui-ripple mdui-float-right mdui-color-theme">注册</button>
                    </div>
                    <div class="mdui-card-content">
                        <p class=" mdui-text-right"><a class="mdui-btn mdui-text-color-theme" href="/Identity/Account/Login">登录</a></p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>




@section Scripts {
    <partial name="_ValidationScriptsPartial" />

    <script>
        $(function () {
            $('#btn_register').click(function () {
                if (!$("#form1").valid()) {
                    return false;
                }

                var postData = $('#form1').formSerialize();

                postData['Input.Email'] = $('#Input_Email').val();
                postData["Input.Password"] = $('#Input_Password').val();
                postData["Input.ConfirmPassword"] = $('#Input_ConfirmPassword').val();

                $.ajax({
                    url: '/Identity/Account/Register',
                    type: 'post',
                    data: postData,
                    dataType: 'json',
                    async: true,
                    success: function (data) {

                        $.loading(true);
                        if (data.state == 'success') {
                            top.$.successLayer('操作成功!正在跳转...');
                            //$('#btn_login').addClass('mdui-text-color-theme').html('登录成功！正在跳转...');
                            setTimeout(function () {
                                window.location.href = '/Identity/Account/Login';
                            }, 500);
                            

                        }
                        else {
                            //$this.removeAttr('disabled');
                            top.$.errorLayer(data.message);
                        }
                    }
                });
            })
        })
    </script>
}
